package example

import (
	"database/sql"
	"fmt"
	"game/game-db/mysql/dao"
	"game/game-db/orm/metag"
	"time"
)

type ExampleAutoEntity struct {
	ExampleParent
	id   int64  `orm:"id=AUTO;name=id;comment=唯一ID"`
	name string `orm:"comment=名字;length=255"`
	num  int64  `orm:"comment=学号"`
	has  bool   `orm:"comment=是否有"`
}

func (t *ExampleAutoEntity) TableMetag() metag.TableMetag {
	tableTag := metag.TableMetag{
		Name:    "example_auto_entity",
		Comment: "例子",
		Indexes: make([]*metag.IndexMetag, 0),
	}
	return tableTag
}

func (t *ExampleAutoEntity) Id() int64 {
	return t.id
}
func (t *ExampleAutoEntity) SetId(id int64) {
	t.id = id
}
func (t *ExampleAutoEntity) SetName(name string) {
	t.name = name
}
func (t *ExampleAutoEntity) SetNum(num int64) {
	t.num = num
}
func (t *ExampleAutoEntity) SetHas(has bool) {
	t.has = has
}
func (t *ExampleAutoEntity) SetSomeInfo(someinfo string) {
	t.someinfo = someinfo
}

func TestExampleAutoEntity(sqlDB *sql.DB) {
	iidao := dao.NewDefaultBaseDao[*ExampleAutoEntity](sqlDB, &ExampleAutoEntity{})
	fmt.Println(iidao.Sql(&ExampleAutoEntity{}))

	var entity ExampleAutoEntity
	// entity.SetName("AAAA")
	entity.SetNum(9875451)
	entity.SetHas(true)
	entity.SetSomeInfo("skdjal4w5e4")
	iidao.Insert(&entity)

	entity.SetSomeInfo("PPPPPP")
	entity.SetInsertTime(time.Now())
	entity.SetUpdateTime(time.Now())
	// iidao.Update(&entity)
	fmt.Println("time.Now()", time.Now().Local(), time.Now())
	fmt.Println("entity", entity)

	obj, _ := iidao.GetByPrimaryKey(int64(1))
	fmt.Println(obj)

	objs := iidao.QueryWhere("")
	fmt.Println("objs", objs)
	for _, objone := range objs {
		fmt.Println(objone, objone.InsertTime(), objone.UpdateTime(), objone.InsertTime().UnixMilli())
	}
}
